package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.AddressBook;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    Orders getById(Long id);

    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    @Select("select count(id) from orders where  status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 根据订单状态和下单时间
     *
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /**
     * 根据动态条件统计营业额
     *
     * @param hashMap
     * @return
     */
    Double sumByMap(HashMap hashMap);

    /**
     * 根据Map获取数量
     *
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 订单搜索
     *
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据ID查询订单
     *
     * @param id
     * @return
     */
//    @Select("select * from orders where id = #{id}")
//    Orders findById(Long id);

    //    @Select("select * from orders where number = #{orderNum}")
//    Orders findOrderByOrderNum(String orderNum);
    @Select("select * from orders where id = #{id}")
    List<OrderDetail> findByOrderId(Long id);
    /**
     * 查询销量排行前10
     */
    List<GoodsSalesDTO> getSaleTop10(@Param("begin") LocalDateTime of, @Param("end") LocalDateTime of1);
}
